  <template> 
	<div class="JNPF-common-layout">
		<div class="JNPF-common-layout-center">
			<el-row class="JNPF-common-search-box" :gutter="16">
				<el-form @submit.native.prevent>
					<el-col :span="6">
						<el-form-item label="辨识评价类型">
							<el-select v-model="query.type" placeholder="辨识评价类型" clearable >
								<el-option v-for="(item, index) in typeOptions" :key="index" :label="item.fullName" :value="item.id"  />
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="风险点名称">
							<el-select v-model="query.point" placeholder="风险点名称" clearable >
								<el-option v-for="(item, index) in pointOptions" :key="index" :label="item.mc" :value="item.Id"  />
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="6">
					<el-form-item>
						<el-button type="primary" icon="el-icon-search" @click="search()">查询</el-button>
						<el-button icon="el-icon-refresh-right" @click="reset()">重置</el-button>
					</el-form-item>
					</el-col>
				</el-form>
			</el-row>
			<div class="JNPF-common-layout-main JNPF-flex-main">
				<div class="JNPF-common-head">
					<div>
					</div>
					<div class="JNPF-common-head-right">
						<el-tooltip effect="dark" content="刷新" placement="top">
							<el-link icon="icon-ym icon-ym-Refresh JNPF-common-head-icon" :underline="false"  @click="reset()" />
						</el-tooltip>
						<screenfull :isContainer="true" />
						<el-tooltip effect="dark" content="列设置" placement="top">
							<el-link icon="icon-ym icon-ym-options JNPF-common-head-icon" :underline="false" />
						</el-tooltip>
					</div>
				</div>
				<JNPF-table v-loading="listLoading" :data="list">
					<el-table-column label="风险点名称"  prop="pointmc" algin="left">
						<template slot-scope="scope">{{ scope.row.pointmc | dynamicText(pointOptions) }}</template>
					</el-table-column>
                    <el-table-column label="风险计划名称"  prop="planmc" algin="left">
					</el-table-column>
					<el-table-column label="辨识评价类型"  prop="type" algin="left">
						<template slot-scope="scope">{{ scope.row.type | dynamicText(typeOptions) }}</template>
					</el-table-column>
					<el-table-column prop="bssj" label="辨识时间" align="left" />
					<el-table-column label="辨识人"  prop="bsr" algin="left">
						<template slot-scope="scope">{{ scope.row.bsr | dynamicText(bsrOptions) }}</template>
					</el-table-column>
					<el-table-column label="评价人"  prop="pjr" algin="left">
						<template slot-scope="scope">{{ scope.row.pjr | dynamicText(pjrOptions) }}</template>
					</el-table-column>
					<el-table-column label="评价方法"  prop="pjff" algin="left">
						<template slot-scope="scope">{{ scope.row.pjff | dynamicText(pjffOptions) }}</template>
					</el-table-column>
					<el-table-column label="状态"  prop="zt" algin="left">
						<template slot-scope="scope">{{ scope.row.zt==0 ? "辨识中" : "已辨识" }}</template>
					</el-table-column>
					<el-table-column prop="pjsj" label="评价时间" align="left" />
					<el-table-column label="操作" fixed="right" width="120">
						<template slot-scope="scope">
                            <el-button type="text" v-if="scope.row.zt==0" @click="RisIdentification(scope.row)">
								风险辨识
							</el-button>
                            <el-button type="text" disabled v-if="scope.row.zt==1" @click="RisIdentification(scope.row)">
								风险辨识
							</el-button>
							<el-button type="text" @click="RisIdentification(scope.row,true)">
								详情
							</el-button>
						</template>
					</el-table-column>
				</JNPF-table>
				<pagination :total="total" :page.sync="listQuery.currentPage" :limit.sync="listQuery.pageSize" @pagination="initData" />
			</div>
		</div>
		<JNPF-Form v-if="formVisible" ref="JNPFForm" @refresh="refresh" />
		<!-- <ExportBox v-if="exportBoxVisible" ref="ExportBox" @download="download" /> -->
	</div>
</template> 
  <script>
    import request from '@/utils/request'
    import {getDictionaryDataSelector} from '@/api/systemData/dictionary'
    import JNPFForm from './Form'
    // import ExportBox from './ExportBox'
    import {previewDataInterface} from '@/api/systemData/dataInterface'

    export default {
        components: {JNPFForm,},
        data() {
            return {
                showAll: false,
                query: {
					type:undefined,
					point:undefined,
                },
                list: [],
                listLoading: true,
                total: 0,
                listQuery: {
					currentPage: 1,
					pageSize: 20,
                    sort: "desc",
                    sidx: "",
                },
                formVisible: false,
                exportBoxVisible: false,
				pointOptions:[],
				typeOptions:[{"fullName":"设备设施","id":"0"},{"fullName":"作业活动","id":"1"},{"fullName":"工艺节点","id":"2"}],
				bsrOptions:[],
				pjrOptions:[],
				pjffOptions:[{"fullName":"LEC","id":"LEC"},{"fullName":"LS","id":"LS"}],
				ztOptions:[{"fullName":"辨识中","id":"0"},{"fullName":"已辨识","id":"1"}],
                fzrOptions:[] // 人
            }
        },
        created() {
			this.initData();
            this.getpointOptions();
            this.getbsrOptions();
            this.getpjrOptions(); 
        },
        methods: {
             // 负责人
            getfzrOptions() {
            return previewDataInterface('8bca424f16d6448ab09e57a028853aa9').then(res => {
                this.fzrOptions = res.data
            })
            },
            getpointOptions() {
                previewDataInterface('aa8f673fa506428eac6adb219a22551d').then(res => {
                    this.pointOptions = res.data
                })
            },
            getbsrOptions() {
                previewDataInterface('8bca424f16d6448ab09e57a028853aa9').then(res => {
                    this.bsrOptions = res.data
                })
            },
            getpjrOptions() {
                previewDataInterface('8bca424f16d6448ab09e57a028853aa9').then(res => {
                    this.pjrOptions = res.data
                })
            },
            async initData() {
                this.listLoading = true;
                await this.getfzrOptions()
                let query = {
                    ...this.listQuery,
                    ...this.query
                };
                request({
                    url: `/api/System/riskPlanpoint`,
                    method: 'get',
                    data: query
                }).then(res => {
                    this.list = res.data.list
                    this.total = res.data.pagination.total
                    // 辨识人
                    if (Array.isArray(this.list)) {
                        this.list.forEach((t, i) => {
                        // if(t.bsr.indexOf("[") >= 0) {
                        //    t.bsr = JSON.parse(t.bsr)
                        // } else {
                        //    t.bsr = t.bsr.split(',')
                        // }
                        t.bsr.indexOf("[") >= 0 ?t.bsr = JSON.parse(t.bsr) :t.bsr = t.bsr.split(',')
                        t.pjr.indexOf("[") >= 0 ?t.pjr = JSON.parse(t.pjr) :t.pjr = t.pjr.split(',')
                        // let bsrPerson = t.bsr.split(',') 
                        // let pjrPerson = t.pjr.split(',')
                        let strArr = []
                        let strArr2 = []
                        this.multiplexing(t.bsr,this.fzrOptions,strArr)
                        this.multiplexing(t.pjr,this.fzrOptions,strArr2)


                        this.list[i].bsr = strArr.join(',')
                        this.list[i].pjr = strArr2.join(',')
                    });
                }
                    this.listLoading = false
                    this.$nextTick(() => {
                        this.tableHeight = "100%"
                    });
                })
            },
            // 复用函数
            multiplexing(arr,arr2,strArr) {
                arr.forEach((j) => {
                    arr2.forEach((k) => {
                    if (k.F_Id == j) { 
                        strArr.push(k.F_RealName)
                    }
                    });
                });
            },
            RisIdentification(id,isDetail) {
                this.formVisible = true
                this.$nextTick(() => {
                    this.$refs.JNPFForm.init(id,isDetail)
                })
            },
            search() {
                this.listQuery = {
                    currentPage: 1,
                    pageSize: 20,

                    sort: "desc",
                    sidx: "",
                }
                this.initData()
            },
            refresh(isrRefresh) {
                this.formVisible = false
                if (isrRefresh) this.reset()
            },
            reset() {
                for (let key in this.query) {
                    this.query[key] = undefined
                }
                this.listQuery = {
                    currentPage: 1,
                    pageSize: 20,

                    sort: "desc",
                    sidx: "",
                }
                this.initData()
            }
        }
    }
</script>